package com.xdr.core.model;

import java.util.Arrays;
import java.util.Date;

import javax.persistence.AttributeOverride;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;


@Entity
@Table(name = "Companies")
@AttributeOverride(name = "id", column = @Column(name = "CompanyId"))
public class Company extends BaseEntity {

	/**
	 * 
	 */
	private static final long serialVersionUID = -252315503049729065L;

	@Column(name = "CompanyName")
	private String companyName;

	@Column(name = "CreatedOn")
	private Date createdOn;

	@Column(name = "IsDeleted")
	private byte isDeleted;

	@Column(name = "Logo")
	private byte[] logo;

	@Column(name = "modifiedOn")
	private String modifiedOn;
	
	@ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE},fetch = FetchType.EAGER)
	@JoinColumn(name="CreatedBy", nullable=true, unique=false)
	private User createdBy;
	
	

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public Date getCreatedOn() {
		return createdOn;
	}

	public void setCreatedOn(Date createdOn) {
		this.createdOn = createdOn;
	}

	public byte getIsDeleted() {
		return isDeleted;
	}

	public void setIsDeleted(byte isDeleted) {
		this.isDeleted = isDeleted;
	}

	public byte[] getLogo() {
		return logo;
	}

	public void setLogo(byte[] logo) {
		this.logo = logo;
	}

	public String getModifiedOn() {
		return modifiedOn;
	}

	public void setModifiedOn(String modifiedOn) {
		this.modifiedOn = modifiedOn;
	}

	public User getCreatedBy() {
		return createdBy;
	}

	public void setCreatedBy(User createdBy) {
		this.createdBy = createdBy;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((companyName == null) ? 0 : companyName.hashCode());
		result = prime * result
				+ ((createdBy == null) ? 0 : createdBy.hashCode());
		result = prime * result
				+ ((createdOn == null) ? 0 : createdOn.hashCode());
		result = prime * result + isDeleted;
		result = prime * result + Arrays.hashCode(logo);
		result = prime * result
				+ ((modifiedOn == null) ? 0 : modifiedOn.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Company other = (Company) obj;
		if (companyName == null) {
			if (other.companyName != null)
				return false;
		} else if (!companyName.equals(other.companyName))
			return false;
		if (createdBy == null) {
			if (other.createdBy != null)
				return false;
		} else if (!createdBy.equals(other.createdBy))
			return false;
		if (createdOn == null) {
			if (other.createdOn != null)
				return false;
		} else if (!createdOn.equals(other.createdOn))
			return false;
		if (isDeleted != other.isDeleted)
			return false;
		if (!Arrays.equals(logo, other.logo))
			return false;
		if (modifiedOn == null) {
			if (other.modifiedOn != null)
				return false;
		} else if (!modifiedOn.equals(other.modifiedOn))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "Company [companyName=" + companyName + ", createdOn="
				+ createdOn + ", isDeleted=" + isDeleted + ", logo="
				+ Arrays.toString(logo) + ", modifiedOn=" + modifiedOn
				+ ", createdBy=" + createdBy + "]";
	}

	public Company(String companyName, Date createdOn, byte isDeleted,
			byte[] logo, String modifiedOn, com.xdr.core.model.User createdBy) {
		super();
		this.companyName = companyName;
		this.createdOn = createdOn;
		this.isDeleted = isDeleted;
		this.logo = logo;
		this.modifiedOn = modifiedOn;
		this.createdBy = createdBy;
	}


}
